#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from requests.exceptions import RequestException
from pyquery import PyQuery as pq

def get_one_page(url):
    try:
        response = requests.get(url)
        response.encoding = 'utf-8'
        if response.status_code == 200:
            return response.text
        else:
            return None
    except RequestException:
        return None

def parse_one_page(html):
    content = pq(html)
    day_weather_list = content('#blk_fc_c0_scroll .blk_fc_c0_i')

    for day_weather in day_weather_list.items():
        date = day_weather.find('.wt_fc_c0_i_date').html()
        temperature = day_weather.find('.wt_fc_c0_i_temp').html()
        tip = day_weather.find('.wt_fc_c0_i_tip').html()
        air = [item.html() for item in day_weather.find('.wt_fc_c0_i_level li').items()]
        print('日期：',date,'，温度：',temperature,'，风：',tip,'，空气质量：',air)

def main():
    url = 'http://weather.sina.com.cn/'
    html = get_one_page(url)
    parse_one_page(html)

if __name__ == '__main__':
    main()